package com.ruoyi.system.utils;

import com.ruoyi.system.domain.*;

import java.util.*;

/**
 * Created On : 2024/4/8.
 * Author : xuliang
 * Description: DataByMonth
 * <p>
 */
public class DataByMonth {

    public static Map<Integer, Map<Integer, List<ProcurementDetail>>> detailByMonth(Map<Integer, List<ProcurementDetail>> dataByYear) {
        Map<Integer, Map<Integer, List<ProcurementDetail>>> dividedData = new HashMap<>();
        // 遍历每一年的数据
        for (Map.Entry<Integer, List<ProcurementDetail>> entry : dataByYear.entrySet()) {
            int year = entry.getKey();
            List<ProcurementDetail> dataList = entry.getValue();
            // 创建当前年份的月份映射
            Map<Integer, List<ProcurementDetail>> dataByMonth = new HashMap<>();
            for (int month = 1; month <= 12; month++) {
                dataByMonth.put(month, new ArrayList<>());
            }
            // 将数据按月份分组
            for (ProcurementDetail data : dataList) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(data.getCreateTime());
                int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
                if (dataByMonth.containsKey(month)) {
                    dataByMonth.get(month).add(data);
                }
            }
            // 将当前年份的月份映射添加到结果中
            dividedData.put(year, dataByMonth);
        }
        return dividedData;
    }

    public static Map<Integer, Map<Integer, List<Direct>>> directByMonth(Map<Integer, List<Direct>> dataByYear) {
        Map<Integer, Map<Integer, List<Direct>>> dividedData = new HashMap<>();
        // 遍历每一年的数据
        for (Map.Entry<Integer, List<Direct>> entry : dataByYear.entrySet()) {
            int year = entry.getKey();
            List<Direct> dataList = entry.getValue();
            // 创建当前年份的月份映射
            Map<Integer, List<Direct>> dataByMonth = new HashMap<>();
            for (int month = 1; month <= 12; month++) {
                dataByMonth.put(month, new ArrayList<>());
            }
            // 将数据按月份分组
            for (Direct data : dataList) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(data.getCreateTime());
                int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
                if (dataByMonth.containsKey(month)) {
                    dataByMonth.get(month).add(data);
                }
            }
            // 将当前年份的月份映射添加到结果中
            dividedData.put(year, dataByMonth);
        }
        return dividedData;
    }

    public static Map<Integer, Map<Integer, List<Labor>>> laborByMonth(Map<Integer, List<Labor>> dataByYear) {
        Map<Integer, Map<Integer, List<Labor>>> dividedData = new HashMap<>();
        // 遍历每一年的数据
        for (Map.Entry<Integer, List<Labor>> entry : dataByYear.entrySet()) {
            int year = entry.getKey();
            List<Labor> dataList = entry.getValue();
            // 创建当前年份的月份映射
            Map<Integer, List<Labor>> dataByMonth = new HashMap<>();
            for (int month = 1; month <= 12; month++) {
                dataByMonth.put(month, new ArrayList<>());
            }
            // 将数据按月份分组
            for (Labor data : dataList) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(data.getCreateTime());
                int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
                if (dataByMonth.containsKey(month)) {
                    dataByMonth.get(month).add(data);
                }
            }
            // 将当前年份的月份映射添加到结果中
            dividedData.put(year, dataByMonth);
        }
        return dividedData;
    }

    public static Map<Integer, Map<Integer, List<Indirect>>> indirectByMonth(Map<Integer, List<Indirect>> dataByYear) {
        Map<Integer, Map<Integer, List<Indirect>>> dividedData = new HashMap<>();
        // 遍历每一年的数据
        for (Map.Entry<Integer, List<Indirect>> entry : dataByYear.entrySet()) {
            int year = entry.getKey();
            List<Indirect> dataList = entry.getValue();
            // 创建当前年份的月份映射
            Map<Integer, List<Indirect>> dataByMonth = new HashMap<>();
            for (int month = 1; month <= 12; month++) {
                dataByMonth.put(month, new ArrayList<>());
            }
            // 将数据按月份分组
            for (Indirect data : dataList) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(data.getCreateTime());
                int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
                if (dataByMonth.containsKey(month)) {
                    dataByMonth.get(month).add(data);
                }
            }
            // 将当前年份的月份映射添加到结果中
            dividedData.put(year, dataByMonth);
        }
        return dividedData;
    }

    public static Map<Integer, Map<Integer, List<Output>>> outputByMonth(Map<Integer, List<Output>> dataByYear) {
        Map<Integer, Map<Integer, List<Output>>> dividedData = new HashMap<>();
        // 遍历每一年的数据
        for (Map.Entry<Integer, List<Output>> entry : dataByYear.entrySet()) {
            int year = entry.getKey();
            List<Output> dataList = entry.getValue();
            // 创建当前年份的月份映射
            Map<Integer, List<Output>> dataByMonth = new HashMap<>();
            for (int month = 1; month <= 12; month++) {
                dataByMonth.put(month, new ArrayList<>());
            }
            // 将数据按月份分组
            for (Output data : dataList) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(data.getCreateTime());
                int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始，需要加1
                if (dataByMonth.containsKey(month)) {
                    dataByMonth.get(month).add(data);
                }
            }
            // 将当前年份的月份映射添加到结果中
            dividedData.put(year, dataByMonth);
        }
        return dividedData;
    }
}
